import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import vueJsx from '@vitejs/plugin-vue-jsx'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({ resolvers: [ElementPlusResolver()] }),
    Components({ resolvers: [ElementPlusResolver()] }),
  ],
  base: './',
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  resolve: {
    // 路径别名
    alias: {
      '@': path.resolve(__dirname, '.', './src/'),
    },
  },
  build: {
    outDir: 'dist_centerSystem',
  },
  server: {
    // 热更新
    hmr: true,
    // 打开端口
    port: 7032,
    // // 代理
    proxy: {
      '/CSapi1': {
        target: 'http://127.0.0.1:7031',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/CSapi1/, ''),
      },
      '/CSapi2': {
        target: 'http://115.190.202.175:80/centenrSystemApi/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/CSapi2/, ''),
      },
      '/RBSapi1': {
        target: 'http://127.0.0.1:7033',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/RBSapi1/, ''),
      },
      '/RBSapi2': {
        target: 'http://115.190.202.175:80/resourcePoolApi/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/RBSapi2/, ''),
      },
      '/ASapi1': {
        target: 'http://127.0.0.1:7037',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/ASapi1/, ''),
      },
      '/ASapi2': {
        target: 'http://115.190.202.175:80/aiServiceApi/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/ASapi2/, ''),
      },
    },
  },
})
